﻿using System;
using System.Collections.Generic;
using Castle.Windsor;
using NUnit.Framework;

namespace WindsorInitConfig {
    [TestFixture]
    public class ResolveWithEnum {
        [Test]
        public void Resolve() {
            var container = new WindsorContainer();
            container.AddComponent<IPreference, MyPreference>();
            var p = container.Resolve<IPreference>(new Dictionary<string, object> {
                {"type", typeof (MyEnumeration)},
            });
            Assert.AreEqual(typeof(MyEnumeration), p.PreferenceType);
        }

        public enum MyEnumeration {
            One = 1,
            Two = 2,
            Three = 3,
        }

        public interface IPreference {
            Type PreferenceType { get; set; }
        }

        public class MyPreference : IPreference {
            public MyPreference(Type type) {
                // Type is required in the construction process 
                PreferenceType = type;
            }

            public Type PreferenceType { get; set; }
        }
    }
}